package com.terra;

import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

// either need the following to prevent a warning on ItemizedOverlay
// or live with the warning.
//@SuppressWarnings(value="all")

public class MapItemizedOverlay<GeoFixProvider> extends ItemizedOverlay {

	private ArrayList<TCOverlayItem> mOverlays = new ArrayList<TCOverlayItem>();
	//private ArrayList<String> Link = new ArrayList<String>();
	
	Context mContext;
		
	public MapItemizedOverlay(Drawable defaultMarker) {
		super(defaultMarker);

	}
	
	public MapItemizedOverlay(Drawable defaultMarker, Context context, MapView mapView) {
		super(boundCenterBottom(defaultMarker));
		  mContext = context;
		}
	
	@Override
	protected OverlayItem createItem(int i) {
	  return mOverlays.get(i);
	}

	@Override
	public int size() {
	  return mOverlays.size();
	}
	
	public int addOverlay(TCOverlayItem overlay, String link) {
	    mOverlays.add(overlay);
	   // setLink(link);
	    populate();
	    return(mOverlays.size());
	}
	
	@Override
	protected boolean onTap(int index) {
	  TCOverlayItem item = mOverlays.get(index);
	  
	  Bundle b = new Bundle();
	  b.putString("TCNAME", item.getDesc());
	  b.putString("TCID", item.getTitle());
	  Log.d("Debug", "Overlay title <"+item.getTitle()+"> Snippet <"+item.getDesc()+">");
	  
	  b.putString("LINK", item.getLink());
	  b.putInt("LAT", item.getPoint().getLatitudeE6());
	  b.putInt("LON", item.getPoint().getLongitudeE6());
	  
	  Intent i = new Intent(mContext, MakeCompassView.class);
	  i.putExtras(b);
	  mContext.startActivity(i);

	  return true;
	}
}

